package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CoachClass;
import com.ruoyi.system.service.ICoachClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 私教课程列表Controller
 * 
 * @author yuanML2018
 * @date 2025-01-04
 */
@RestController
@RequestMapping("/system/class")
public class CoachClassController extends BaseController
{
    @Autowired
    private ICoachClassService coachClassService;

    /**
     * 查询私教课程列表列表
     */
    @PreAuthorize("@ss.hasPermi('system:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(CoachClass coachClass)
    {
        startPage();
        List<CoachClass> list = coachClassService.selectCoachClassList(coachClass);
        return getDataTable(list);
    }

    /**
     * 导出私教课程列表列表
     */
    @PreAuthorize("@ss.hasPermi('system:class:export')")
    @Log(title = "私教课程列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CoachClass coachClass)
    {
        List<CoachClass> list = coachClassService.selectCoachClassList(coachClass);
        ExcelUtil<CoachClass> util = new ExcelUtil<CoachClass>(CoachClass.class);
        util.exportExcel(response, list, "私教课程列表数据");
    }

    /**
     * 获取私教课程列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:class:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(coachClassService.selectCoachClassById(id));
    }

    /**
     * 新增私教课程列表
     */
    @PreAuthorize("@ss.hasPermi('system:class:add')")
    @Log(title = "私教课程列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CoachClass coachClass)
    {
        return toAjax(coachClassService.insertCoachClass(coachClass));
    }

    /**
     * 修改私教课程列表
     */
    @PreAuthorize("@ss.hasPermi('system:class:edit')")
    @Log(title = "私教课程列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CoachClass coachClass)
    {
        return toAjax(coachClassService.updateCoachClass(coachClass));
    }

    /**
     * 删除私教课程列表
     */
    @PreAuthorize("@ss.hasPermi('system:class:remove')")
    @Log(title = "私教课程列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(coachClassService.deleteCoachClassByIds(ids));
    }
}
